//
//  UserContentViewController.swift
//  Core note
//
//  Created by 仙女瑶  on 2017/9/16.
//  Copyright © 2017年 Mac . All rights reserved.
//

import UIKit
import CoreData
class UserContentViewController: UIViewController {

    @IBOutlet weak var tfName: UITextField!
    @IBOutlet weak var tfAge: UITextField!
    var data : NSManagedObject!
    @IBOutlet weak var tfNum: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
     self.tfName.text = self.data.value(forKey: "name") as! String?
        self.tfAge.text = "\(self.data.value(forKey: "age")!)"
        self.tfNum.text = self.data.value(forKey: "num") as! String?
        
        // Do any additional setup after loading the view.
    }
//修改数据
    @IBAction func submitBtnPressed(_ sender: Any) {
        self.data.setValue(self.tfName.text, forKey: "name")
        self.data.setValue(Int(self.tfAge.text!), forKey: "age")
        self.data.setValue( self.tfNum.text, forKey:  "num")
        try! self.data.managedObjectContext?.save()
        let _ = self.navigationController?.popViewController(animated: true)
        
    }
    @IBAction func concealBtnPressed(_ sender: Any) {
        let _ = self.navigationController?.popViewController(animated: true)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
